package com.youlu.campus.common.utils;

import java.time.LocalDate;

/**
 * 用于管理 Redis key的使用
 *
 * @Description: RedisKeyUtil
 * @Date 2025/6/20
 * @author: su
 */
public enum RedisKeyUtil {

    USER_INFO("user.info.%s", "用户详情缓存key"),
    LOGIN_SMS_CODE("com.luyou.login-sms-code.%s", "登录验证码缓存key"),
    ACCESS_TOKEN_WECHAT_H5_PRE_FIX("com.luyou.wechat.h5.access-token.%s.%s", "微信h5token 缓存"),
    TOKEN_KEY_WECHAT_H5("youlu:dt:wechat:h5:%s", "微信h5token缓存"),
    PHONE_CODE_WECHANT_MERCHANT("phone_code:wechant_merchant_config", "微信商户配置验证码"),
    PHONE_CODE_PLATFORM_CONFIG("phone_code:platform_config", "平台配置 验证码"),
    UNIVERSITY_RANK_PRE_KEY("com.luyou.rank.university.h5-plus.activityId:%s", "高校排行榜Key"),
    UNIVERSITY_RANK_LIST_KEY("com.luyou.unversity.rank.acitivityId:%s:taskId:%s", "大学排名key"),
    WECHAT_BLACK_LIST_APPID("wechat.black.list:%s", "微信黑名单"),
    PLATFORM_DOMAIN_CONFIG("platform.domain.config:%s", "平台域名配置缓存key"),
    WECAHT_CONFIG_INFO_KEY("wechat.config.info:%s", "微信配置详情"),
    //ai
    CHAT_ASSISTANT_SYSTEM_MESSAGE("chat:assistant:system_message", "campus-ai 聊天 助手 systemMessage 缓存"),
    CHAT_ASSISTANT_HELLO("chat:assistant:hello", "campus-ai 聊天 助手 hello 缓存"),
    //用户助力
    USER_HELP_NUMBER_KEY("user:help:number:%s:%s:%s:%s", "今日用户助力key"),
    USER_HELP_LOCK_KEY("user:invite:lock:%s:%s:%s:%s:%s", "用户助力 锁 key"),
    USER_HELP_INVITE_NUMBER_KEY("user:invite:number:%s:%s:%s:%s", "用户助力 邀请人数key"),
    //用户黑名单
    USER_BLACK_LIST_KEY("user.black:%s", "用户黑名单"),
    //活动
    ACTIVITY_INFO("campus:activity:info:%s", "活动详情缓存 key"),
    CAMPUS_USER_INVITE_LOCK("campus:user_invite:%s_%s_%s", "用户邀请 锁key"),
    ACTIVITY_SIGN_UP_LOCK("campus:activity_sign_up_lock:%s:%s", "用户报名锁key"),

    ACTIVITY_PLATFORM_IMPORT_LOCK("activity.platform.import.lock:%s", "活动导入锁"),
    // 活动抽奖
    ACTIVITY_LOTTERY_DRAW_LOCK("activity.lottery.draw:%s:%s", "活动抽奖key 锁"),
    ACTIVITY_LOTTERY_USER_TODAY_COUNT_KEY("lottery.user.today-count:%s:%s:%s", "用户今日抽奖次数"),
    ACTIVITY_LOTTERY_PRIZE("activity.lottery.prize:%s", "活动抽奖奖品key"),
    ACTIVITY_LOTTERY_PRIZE_WIN_COUNT("activity.lottery.prize.win-count:%s", "活动抽奖奖品 中奖次数 key"),
    TASK_ACTIVITY_RANDOM_NUM_LOCK("task.activity.random.num.lock", "定时任务 活动随机数 redis 锁 key"),

    ORDER_PAYMENT_SMS("order.pay.%s:%s:%s", "订单支付完成发送短信"),
    SMS_TEMPLATE("sms.template:%s_%s", "短信模板"),
    WECAHT_MERCHANT_CONFIG_MERCHANT_ID("wechat.merchant.config.merchant-id:%s", "通过商户id获取微信商户配置key"),
    WECAHT_MERCHANT_CONFIG_PLATFORM_SERIAL_NUMBER("wechat.merchant.config.platform-serial-number:%s", "通过平台流水号获取微信商户配置key"),
    DOMAIN_RECORD_ADD_KEY("domain.record.add", "域名解析记录新增key"),


    //campus-statistics
    STATISTICS_BAO_MING_DAY("statistics:baoming_user:day:%s:%s", ""),
    STATISTICS_BAO_MING_HOUR("statistics:baoming_user:hour:%s:%s:%s", "报名统计"),
    STATISTICS_PV_ACTIVITY_KEY("statistics:vote.pv.activityId:%s", "pv统计"),
    STATISTICS_QA_BAO_MING_DAY("statistics:user_baoming:day:%s:%s:%s", "答题报名每日统计"),
    STATISTICS_QA_BAO_MING_DAY_HOUR("statistics:user_baoming:day:hour:%s:%s:%s:%s", "答题报名每日每时统计"),
    STATISTICS_ORDER_GMV("statistics:order_gmv:%s", ""),
    STATISTICS_QA_DAY("statistics:activity_user_qa:day:%s:%s:%s", ""),
    STATISTICS_QA_DAY_HOUR("statistics:activity_user_qa:hour:%s:%s:%s:%s", ""),
    STATISTICS_QA_USER_DAY("statistics:qa_user:day:%s:%s", ""),
    STATISTICS_QA_USER_DAY_HOUR("statistics:qa_useR:hour:%s:%s:%s", ""),
    STATISTICS_PLATFORM_CONFIG("statistics:sys_platform_config:%s", "统计平台配置缓存前缀"),
    STATISTICS_ACTIVITY_INVITE_COUNT_LOCK("statistics:activity_invite_count_lock:%s", "活动统计锁key"),

    ;


    private String key;
    private String description;

    public static String getActivityPlatformImportLock() {
        return ACTIVITY_PLATFORM_IMPORT_LOCK.getKey();
    }

    public String getKey() {
        return key;
    }

    RedisKeyUtil(String key, String description) {
        this.key = key;
        this.description = description;
    }

    public static String getDomainRecordAddKey() {
        return RedisKeyUtil.DOMAIN_RECORD_ADD_KEY.getKey();
    }

    public static String getWechatMerchantConfigByPlatformSerialNumber(String platformSerialNumber) {
        return String.format(RedisKeyUtil.WECAHT_MERCHANT_CONFIG_PLATFORM_SERIAL_NUMBER.getKey(), platformSerialNumber);
    }

    public static String getWechatMerchantConfigByMechantId(String merchantId) {
        return String.format(RedisKeyUtil.WECAHT_MERCHANT_CONFIG_MERCHANT_ID.getKey(), merchantId);
    }

    public static String getSmsTemplateKey(String sign, String type) {
        return String.format(RedisKeyUtil.SMS_TEMPLATE.getKey(), sign, type);
    }


    public static String getOrderPaymentSms(String userId, String activityId) {
        return String.format(RedisKeyUtil.ORDER_PAYMENT_SMS.getKey(), LocalDate.now(), userId, activityId);
    }

    public static String getUserBlackListKey(String userId) {
        return String.format(RedisKeyUtil.USER_BLACK_LIST_KEY.getKey(), userId);
    }

    public static String getWechatConfigInfoKey(String appId) {

        return String.format(RedisKeyUtil.WECAHT_CONFIG_INFO_KEY.getKey(), appId);
    }

    public static String getPlatformDomainConfigKey(String domain) {
        return String.format(RedisKeyUtil.PLATFORM_DOMAIN_CONFIG.getKey(), domain);
    }

    /**
     * 获取微信黑名单key
     *
     * @param sysAppId
     * @return
     */
    public static String getWechatBlackListKey(String sysAppId) {
        return String.format(RedisKeyUtil.WECHAT_BLACK_LIST_APPID.getKey(), sysAppId);
    }

    public static String getActivityInfoKey(String activityId) {
        return String.format(RedisKeyUtil.ACTIVITY_INFO.getKey(), activityId);
    }

    public static String getCampusUserInviteLock(String activityId, String userId, String inviteUserId) {
        return String.format(RedisKeyUtil.CAMPUS_USER_INVITE_LOCK.getKey(), activityId, userId, inviteUserId);
    }

    public static String getActivitySignUpLock(String activityId, String userId) {
        return String.format(RedisKeyUtil.ACTIVITY_SIGN_UP_LOCK.getKey(), activityId, userId);
    }

    public static String getTaskActivityRandomNumLock() {
        return RedisKeyUtil.TASK_ACTIVITY_RANDOM_NUM_LOCK.getKey();
    }

    public static String getPhoneCodeWechantMerchant() {
        return RedisKeyUtil.PHONE_CODE_WECHANT_MERCHANT.getKey();
    }

    public static String getPhoneCodePlatformConfig() {
        return RedisKeyUtil.PHONE_CODE_PLATFORM_CONFIG.getKey();
    }

    public static String getUniversityContestRankingCountKey(String activityId, String taskId) {
        return String.format(RedisKeyUtil.UNIVERSITY_RANK_LIST_KEY.getKey(), activityId, taskId);
    }

    public static String getUniversityRankPreKey(String activityId) {
        return String.format(RedisKeyUtil.UNIVERSITY_RANK_PRE_KEY.getKey(), activityId);
    }

    public static String getActivityLotteryDrawLock(String userId, String activityId) {
        return String.format(RedisKeyUtil.ACTIVITY_LOTTERY_DRAW_LOCK.getKey(), userId, activityId);
    }

    public static String getActivityLotteryUserTodayCountKey(String userId, String activityId) {
        return String.format(RedisKeyUtil.ACTIVITY_LOTTERY_USER_TODAY_COUNT_KEY.getKey(), LocalDate.now(), userId, activityId);
    }

    public static String getUserHelpNumerKey(String activityId, String taskId, String userId) {
        return String.format(RedisKeyUtil.USER_HELP_NUMBER_KEY.getKey(), activityId, taskId, userId, LocalDate.now());
    }

    public static String getUserHelpLockKey(String activityId, String taskId, String invitedByUserId, String targetUserId) {
        return String.format(RedisKeyUtil.USER_HELP_LOCK_KEY.getKey(), activityId, taskId, invitedByUserId, targetUserId, LocalDate.now());
    }


    public static String getUserHelpInviteNumberKey(String activityId, String taskId, String userId) {
        return String.format(RedisKeyUtil.USER_HELP_INVITE_NUMBER_KEY.getKey(), activityId, taskId, userId, LocalDate.now());
    }


    public static String getActivityLotteryPrize(String prizeId) {
        return String.format(RedisKeyUtil.ACTIVITY_LOTTERY_PRIZE.getKey(), prizeId);
    }

    public static String getActivtyLotteryPrizeWinCount(String configPrizeId) {
        return String.format(RedisKeyUtil.ACTIVITY_LOTTERY_PRIZE_WIN_COUNT.getKey(), configPrizeId);
    }

    public static String getChatAssistantSystemMessage(String id) {
        return RedisKeyUtil.CHAT_ASSISTANT_SYSTEM_MESSAGE.getKey();
    }

    public static String getChatAssistantHello(String id) {
        return RedisKeyUtil.CHAT_ASSISTANT_HELLO.getKey();
    }


    public static String getUserInfoKey(String token) {
        return String.format(RedisKeyUtil.USER_INFO.getKey(), token);
    }

    public static String getTokenKeyWechatH5(String openId) {
        return String.format(RedisKeyUtil.TOKEN_KEY_WECHAT_H5.getKey(), openId);
    }

    public static String getAccessTokenWechatH5(String appId, String openId) {
        return String.format(RedisKeyUtil.ACCESS_TOKEN_WECHAT_H5_PRE_FIX.getKey(), appId, openId);
    }

    public static String getLoginSmsCodeKey(String phone) {
        return String.format(RedisKeyUtil.LOGIN_SMS_CODE.getKey(), phone);
    }

    public static String getStatisticsBaoMingDAY(String userId, Integer currentDate) {
        return String.format(STATISTICS_BAO_MING_DAY.getKey(), userId, currentDate);
    }

    public static String getStatisticsBaoMingHour(String userId, Integer currentDate, String currentHour) {
        return String.format(STATISTICS_BAO_MING_HOUR.getKey(), userId, currentDate, currentHour);
    }

    public static String getStatisticsPvActivityKey(String activityId) {
        return String.format(STATISTICS_PV_ACTIVITY_KEY.getKey(), activityId);
    }

    public static String getStatisticsQaBaoMingDay(String userId, Integer currentDate, String activityId) {
        return String.format(STATISTICS_QA_BAO_MING_DAY.getKey(), userId, currentDate, activityId);
    }

    public static String getStatisticsQaBaoMingDayHour(String userId, Integer currentDate, String currentHour, String activityId) {
        return String.format(STATISTICS_QA_BAO_MING_DAY_HOUR.getKey(), userId, currentDate, currentHour, activityId);
    }

    public static String getStatisticsOrderGmv(String orderNo) {
        return String.format(STATISTICS_ORDER_GMV.getKey(), orderNo);
    }

    public static String getStatisticsQaDay(String userId, Integer currentDate, String activityId) {
        return String.format(STATISTICS_QA_DAY.getKey(), userId, currentDate, activityId);
    }

    public static String getStatisticsQaDayHour(String userId, Integer currentDate, String currentHour, String activityId) {
        return String.format(STATISTICS_QA_DAY_HOUR.getKey(), userId, currentDate, currentHour, activityId);
    }

    public static String getStatisticsQaUserDay(String userId, Integer currentDate) {
        return String.format(STATISTICS_QA_USER_DAY.getKey(), userId, currentDate);
    }

    public static String getStatisticsQaUserDayHour(String userId, Integer currentDate, String currentHour) {
        return String.format(STATISTICS_QA_USER_DAY_HOUR.getKey(), userId, currentDate, currentHour);
    }

    public static String getStatisticsPlatformConfig(String systemAppId) {
        return String.format(STATISTICS_PLATFORM_CONFIG.getKey(), systemAppId);
    }

    public static String getStatisticsActivityInviteCountLock(String activityId) {
        return String.format(STATISTICS_ACTIVITY_INVITE_COUNT_LOCK.getKey(), activityId);
    }
}
